package h_10_12;

public class Main2 {
    /**
     * 1343. 大小为 K 且平均值大于等于阈值的子数组数目
     * https://leetcode.cn/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/description/
     * @param arr
     * @param k
     * @param threshold
     * @return
     */
    public int numOfSubarrays(int[] arr, int k, int threshold) {
        int sum = 0;
        int ret = 0;
        for(int i = 0;i < arr.length;i++) {
            // 入
            sum += arr[i];

            // 判断
            int left = i - k + 1;
            if(left < 0) {
                continue;
            }

            // 更、出
            // double x = (double) sum / k;
            // if(x >= threshold) {
            //     ret++;
            // }
            if(sum >= k * threshold) {
                ret++;
            }

            sum -= arr[left];
        }
        return ret;
    }
}
